package edu.whu.rose.clock.ssql.binding;

import com.sleepycat.bind.tuple.TupleBinding;
import com.sleepycat.bind.tuple.TupleInput;
import com.sleepycat.bind.tuple.TupleOutput;

import edu.whu.rose.clock.kps.spindex.ShortestPathIndexItem;

public class ShortestPathIndexItemBinding extends TupleBinding {

	public Object entryToObject(TupleInput input) {
		int size = input.readInt();
		int[] distances= new int[size];
		for (int i = 0; i < size; i++) {
			distances[i] = input.readInt();
		}
		int[] predecessors = new int[size];
		for (int i = 0; i < size; i++) {
			predecessors[i] = input.readInt();
		}
		return new ShortestPathIndexItem(distances, predecessors);
	}

	public void objectToEntry(Object object, TupleOutput output) {
		ShortestPathIndexItem spii = (ShortestPathIndexItem) object;
		int size = spii.size();
		output.writeInt(size);
		int[] distances = spii.getDistances();
		for (int i = 0; i < size; i++) {
			output.writeInt(distances[i]);
		}
		int[] predecessors = spii.getPredecessors();
		for (int i = 0; i < size; i++) {
			output.writeInt(predecessors[i]);
		}
	}

}
